package cz.uhk.ppro.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import cz.uhk.ppro.form.DilForm;

public class DilValidator implements Validator{

	public boolean supports(Class<?> clazz) {
		return DilForm.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "katalogoveCislo", "katC.required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nazev", "dilNazev.required");
		DilForm df = (DilForm)target;
		if (df.getDodavatel() == 0) {
			errors.rejectValue("dodavatel", "dilDodavatel.required");
		}
		if (df.getStitky().size()==0) {
			errors.rejectValue( "stitky", "dilStitky.required");
		}
	}

}
